package com.bnyy.message.enums;

import java.io.Serializable;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2022/11/11
 **/
public enum MessageType implements Serializable {

    UNKNOWN,
    GROUP_CHAT_CREATED(1, "创建群聊"),
    STRANGER(2, "陌生人消息"),

    LOGIN(101, "登录"),
    LOGOUT(102, "退出登录"),

    REQUEST_AUTHORITY(2000, "请求位置权限"),
    RECEIVE_REQUEST_AUTHORITY(2001, "收到请求位置权限"),
    CHECK_AUTH(2002, "检查位置权限"),

    CHAT_IMAGE(4000, "图片"),
    CHAT_AUDIO(4001, "语音"),
    CHAT_TEXT(4002, "文字"),
    CHAT_TIPS(4030, "消息提示"), // type : 1:个人主页 2:群投票 3:群活动

    GROUP_CHAT_MEMER_ADD(4003, "群聊新增成员"),
    GROUP_CHAT_MEMER_REMOVE(4004, "群聊移除成员"),
    GROUP_CHAT_DISMISS(4005, "群聊解散"),
    GROUP_CHAT_EDIT_NAME(4006, "群聊名称修改"),
    GROUP_CHAT_NOTICE(4007, "群公告"),
    GROUP_CHAT_INVITATION(4013, "邀请加入群聊"),
    GROUP_CHAT_VERIFICATION(4015, "加入群聊验证"),
    GROUP_CHAT_MANAGER_ADD(4016, "群聊新增管理员"),
    GROUP_CHAT_MANAGER_REMOVE(4017, "群聊移除管理员"),
    GROUP_CHAT_TABOO(4018, "群聊禁言"),
    GROUP_CHAT_TABOO_RELIEVE(4019, "群聊解除禁言"),
    GROUP_CHAT_VOTE(4029, "发起投票"),
    GROUP_CHAT_ACTIVITY(4031, "发起群活动"),

    MALL_GOODS(4008, "商城商品"),
    SERVICE_GOODS(4009, "服务商品"),
    ALARM(4010, "发起救援"),
    FENCE(4011, "电子围栏"),
    HEALTH_WEEKLY(4012, "健康周报"),
    USER_HOMEPAGE(4014, "个人主页"),
    HEALTH_ALERT(4020, "健康数据警戒"),
    ARTICLE(4032, "文章"),

    SEND_FAIL_STRANGER(4021, "私聊发送失败,陌生人发送次数限制"),
    SEND_FAIL_LIMIT(4022, "私聊发送失败-聊天限制通知"),
    SEND_FAILED,

    NOTICE_NEW_FANS(4023, "新朋友"),
    NOTICE_ALARM(4024, "紧急救援"),
    NOTICE_LOCATION_AUTHORITY(4025, "位置授权"),
    NOTICE_GOODS(4026, "服务通知"); //  type : 1:普通商品 2:拼团商品 3:服务商品

    private int type;
    private String name;

    MessageType() {
    }

    MessageType(int type, String name) {
        this.type = type;
        this.name = name;
    }

    public int getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    /**
     * 是否聊天消息
     * @return
     */
    public boolean isChatMessage() {
        return isChatMessage(this);
    }

    /**
     * 是否提示消息
     * @return
     */
    public boolean isTipsChatMessage() {
        return isChatTips(this);
    }

    public boolean isNoticeMessage() {
        return isNoticeMessage(this);
    }


    @Override
    public String toString() {
        return "MessageType {" +
                "type =" + type +
                ", name ='" + name + '\'' +
                ", isChatMessage ='" + isChatMessage() + '\'' +
                ", isTipsChat ='" + isTipsChatMessage() + '\'' +
                '}';
    }

    public static MessageType getMessageType(int type) {
        for (MessageType messageType : values()) {
            if (messageType.type == type) {
                return messageType;
            }
        }
        return UNKNOWN;
    }

    private static boolean isNoticeMessage(MessageType messageType) {
        switch (messageType) {
            case NOTICE_GOODS:
            case NOTICE_LOCATION_AUTHORITY:
            case NOTICE_ALARM:
            case NOTICE_NEW_FANS:
                return true;
        }
        return false;
    }

    private static boolean isChatMessage(MessageType messageType) {
        if (isChatTips(messageType)) {
            return true;
        } else {
            switch (messageType) {
                case CHAT_IMAGE:
                case CHAT_AUDIO:
                case CHAT_TEXT:
                case GROUP_CHAT_INVITATION:
                case GROUP_CHAT_VERIFICATION:
                case MALL_GOODS:
                case SERVICE_GOODS:
                case ALARM:
                case FENCE:
                case HEALTH_WEEKLY:
                case USER_HOMEPAGE:
                case HEALTH_ALERT:
                case SEND_FAILED:
                case GROUP_CHAT_NOTICE:
                case GROUP_CHAT_VOTE:
                case GROUP_CHAT_ACTIVITY:
                case ARTICLE:
                    return true;
            }
            return false;
        }
    }

    private static boolean isChatTips(MessageType messageType) {
        switch (messageType) {
            case GROUP_CHAT_CREATED:
            case GROUP_CHAT_TABOO:
            case GROUP_CHAT_MEMER_ADD:
            case GROUP_CHAT_MEMER_REMOVE:
            case GROUP_CHAT_DISMISS:
            case GROUP_CHAT_EDIT_NAME:
            case GROUP_CHAT_MANAGER_ADD:
            case GROUP_CHAT_MANAGER_REMOVE:
            case GROUP_CHAT_TABOO_RELIEVE:
            case SEND_FAIL_STRANGER:
            case SEND_FAIL_LIMIT:
            case CHAT_TIPS:
                return true;
        }
        return false;
    }
}



























